package util;

import java.util.Random;

/**
 * @author NAME-L
 * @Description 工具类
 * @className StringUtils
 * @date 2022-03-20 18:45:21
 */
public class StringUtils {

    /**
     * 生成随机字符串
     * @param length 长度
     * @return string
     */
    public static String getRandomString(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }

    public static String arrToString(String[] arr) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("[");
        for (int i=0; i<arr.length; i++) {
            if (i == arr.length-1) {
                buffer.append('\'').append(arr[i]).append('\'').append("]");
            } else {
                buffer.append('\'').append(arr[i]).append('\'').append(",");
            }
        }
        return buffer.toString();
    }
}
